package org.jeecg.modules.iot.api;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.iot.api.fallback.ControlApiFallback;
import org.jeecg.modules.iot.model.Location;
import org.jeecg.modules.iot.model.LocationJson;
import org.jeecg.modules.iot.model.RentalSocketDevice;
import org.jeecg.modules.iot.model.control.CentralControlConfig;
import org.jeecg.modules.iot.model.control.SpeedOtherConfig;
import org.jeecg.modules.iot.model.power.TaiPower;
import org.jeecg.modules.iot.req.OpenSocketReq;
import org.jeecg.modules.iot.req.CloseSocketReq;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

@FeignClient(value = "jeecg-iot", fallbackFactory = ControlApiFallback.class)
public interface IControlAPI {

    // ---------- 推送电单车信息 ----------
    @PostMapping("/iot/car/pushInfo/{imei}")
    Boolean pushEBikeInfo(@PathVariable String imei);
    // ---------- 车辆控制 ----------
    @PostMapping("/iot/car/openCar/{imei}/{sn}")
    Boolean openCar(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/closeCar/{imei}/{sn}")
    Boolean closeCar(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/defenseCar/{imei}/{sn}")
    Boolean defenseCar(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/disarmingCar/{imei}/{sn}")
    Boolean disarmingCar(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/handleLockOpen/{imei}/{sn}")
    Boolean handleLockOpen(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/handleLockClose/{imei}/{sn}")
    Boolean handleLockClose(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/searchCar/{imei}/{sn}")
    Boolean searchCar(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/seatLock/{imei}/{sn}")
    Boolean seatLock(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/setVolume/{imei}/{sn}")
    Boolean setVolume(@PathVariable String imei, @PathVariable String sn, @RequestParam Integer volume);

    @PostMapping("/iot/car/pairRemoteControl/{imei}/{sn}")
    Boolean pairRemoteControl(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/clearRemoteControl/{imei}/{sn}")
    Boolean clearRemoteControl(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/setPlayAudio/{imei}/{sn}")
    Boolean setPlayAudio(@PathVariable String imei, @PathVariable String sn, @RequestParam Byte audioIndex);

    @PostMapping("/iot/car/returnCar/{imei}/{sn}")
    Result returnCar(@PathVariable String imei, @PathVariable String sn);

    @GetMapping("/iot/car/getSportModeStatus") //  假设远程接口的路径是 /car/getSportModeStatus
    Boolean  getSportModeStatus(
            @PathVariable(name = "terminalId") String terminalId,
            @PathVariable(name = "phone") String phone
    );

    // ---------- 车辆查询 ----------
    @PostMapping("/iot/car/queryLocation/{imei}/{sn}")
    Result queryLocation(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/queryControl/{imei}/{sn}")
    String queryControl(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/car/queryControlByaddress/{imei}/{sn}")
    String queryControlByaddress(@PathVariable String imei, @PathVariable String sn, @RequestParam String adress);

    @PostMapping("/iot/car/queryControlByaddress/{imei}/{sn}")
    String queryControlByaddress(@RequestParam String adress);


    // ---------- 控制器配置 ----------
    @PostMapping("/iot/config/setEstimatedRemainingMileage/{imei}/{sn}") // Changed to PostMapping
    Result setEstimatedRemainingMileage(@PathVariable String imei, @PathVariable String sn, @RequestParam("orgCode") Integer mileage);

    @PostMapping("/iot/config/setSpeed/{imei}/{sn}") // Changed to PostMapping
    Result setSpeed(@PathVariable String imei, @PathVariable String sn, @RequestBody SpeedOtherConfig speedOtherConfig);

    @PostMapping("/iot/config/setCentralControlConfig/{imei}/{sn}") // Changed to PostMapping
    Result setCentralControlConfig(@PathVariable String imei, @PathVariable String sn, @RequestBody CentralControlConfig centralControlConfig);

    @PostMapping("/iot/config/setPolePairNumber/{imei}/{sn}") // Changed to PostMapping
    Result setPolePairNumber(@PathVariable String imei, @PathVariable String sn, @RequestParam Integer polePairs); // Changed to RequestParam

    @PostMapping("/iot/config/setTailLightConfig/{imei}/{sn}") // Changed to PostMapping
    Result setTailLightConfig(@PathVariable String imei, @PathVariable String sn, @RequestParam boolean lightOn, @RequestParam boolean blinkMode, @RequestParam int blinkTimes); // Changed to RequestParam


    @PostMapping("/iot/config/setBatteryVoltageAndCurrentLimit/{imei}/{sn}") // Changed to PostMapping
    Result setBatteryVoltageAndCurrentLimit(@PathVariable String imei, @PathVariable String sn, @RequestParam Integer batteryVoltageType, @RequestParam Integer currentLimit); // Changed to RequestParam

    @PostMapping("/iot/config/setUndervoltageProtection/{imei}/{sn}") // Changed to PostMapping, Removed duplicate method
    Result setUndervoltageProtection(@PathVariable String imei, @PathVariable String sn, @RequestParam Float undervoltageProtection); // Changed to RequestParam

    @PostMapping("/iot/config/setBrakeAndAssistConfig/{imei}/{sn}") // Changed to PostMapping
    Result setBrakeAndAssistConfig(@PathVariable String imei, @PathVariable String sn, @RequestParam boolean brakeEnergyRecoveryEnabled, @RequestParam boolean handleBrakeEnergyRecoveryEnabled, @RequestParam boolean handleReleasePowerEnabled, @RequestParam Integer recoveryIntensity, @RequestParam Integer assistIntensity, @RequestParam boolean handleCruiseControlEnabled, @RequestParam boolean buttonCruiseControlEnabled); // Changed to RequestParam


    @PostMapping("/iot/config/setSpeedPercentages/{imei}/{sn}") // Changed to PostMapping
    Result setSpeedPercentages(@PathVariable String imei, @PathVariable String sn, @RequestParam Integer gear1Percentage, @RequestParam Integer gear2Percentage); // Changed to RequestParam

    // ---------- 位置信息 ----------
    @GetMapping("/iot/location/queryLocationByDeviceId/{imei}")
    Location queryLocationByDeviceId(@PathVariable String imei);  // Added sn


    @GetMapping("/iot/location/queryLocationsByTimeRange")
    List<LocationJson> queryLocationsByTimeRange(@RequestParam String imei , @RequestParam Timestamp startTime, @RequestParam Timestamp endTime); // Changed to RequestParam

    @GetMapping("/iot/power/queryLoByTimeRange/{imei}/{sn}") // Assuming this is related to location
    List<LocationJson> queryLoByTimeRange(@RequestParam String imei,   @RequestParam Timestamp startTimestamp, @RequestParam Timestamp endTimestamp); // Changed to RequestParam

    @GetMapping("/iot/location/startLocationTrack/{imei}/{sn}") // Moved to location section
    Boolean startLocationTrack(@PathVariable String imei, @PathVariable String sn, @RequestParam Short timeInterval, @RequestParam int validityPeriod); // Changed to RequestParam

    @GetMapping("/iot/location/queryByDeviceId/{deviceId}")
    Location queryLByDeviceId(@PathVariable String deviceId);

    @GetMapping("/iot/location/gpsToGcj02/{latitude}/{longitude}")
    double[] gpsToGcj02(@PathVariable double latitude, @PathVariable double longitude);

    // ---------- 电量信息 ----------
    @GetMapping("/iot/bms/queryTaiPowerLastByDeviceId/{imei}")
    TaiPower queryTaiPowerLastByDeviceId(@PathVariable String imei);

    // ----------  Socket 设备信息 ----------
    @GetMapping("/iot/power/selectOneRentalScoket/{imei}/{sn}") // Typo corrected: Scoket -> Socket
    RentalSocketDevice selectOneRentalScoket(@PathVariable String imei, @PathVariable String sn);


    // ---------- 充电桩 ----------
    @PostMapping("/iot/chargePile/queryPort/{imei}/{sn}") // Using PostMapping for consistency
    Result queryPort(@PathVariable String imei, @PathVariable String sn);


    @GetMapping("/iot/chargePile/queryPort") // Using PostMapping for consistency
    Integer queryPort(@RequestParam String deviceCode);



    // ---------- BMS ----------
    @GetMapping("/iot/bms/queryBMSPower/{imei}/{sn}")
    Integer queryBMSPower(@PathVariable String imei, @PathVariable String sn);


    @GetMapping("/iot/bms/setContinuousVoltage/{imei}/{sn}")
    Integer setContinuousVoltage(@PathVariable String imei, @PathVariable String sn, @RequestParam Boolean isContinuousVoltage);




    @PostMapping("/iot/bms/queryPower/{imei}/{sn}")
    Integer queryPower(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/bms/setPower/{imei}/{sn}")
    Integer setPower(@PathVariable String imei, @PathVariable String sn,@PathVariable Boolean powerOffMode, @PathVariable int currentLimit, @PathVariable int timeLimit);






    @PostMapping("/iot/bms/queryDeviceId/{imei}/{sn}")
    Integer queryDeviceId(@PathVariable String imei, @PathVariable String sn);

    // ---------- 控制命令 ----------
    @PostMapping("/iot/control/setWheelDiameter/{imei}/{sn}")
    Result<Void> setWheelDiameter(@PathVariable String imei, @PathVariable String sn, @RequestParam Integer wheelDiameter);

    @PostMapping("/iot/car/enableSportMode/{imei}/{sn}")
    Boolean enableSportMode(@PathVariable String imei,@PathVariable String sn,@RequestParam Boolean enable);
    /*@PostMapping("/iot/control/setBrakeAndAssistConfig/{imei}/{sn}")
    Result<Void> setBrakeAndAssistConfig(@PathVariable String imei, @PathVariable String sn,
                                         @RequestParam Boolean brakeEnergyRecoveryEnabled,
                                         @RequestParam Boolean handleBrakeEnergyRecoveryEnabled,
                                         @RequestParam Boolean handleReleasePowerEnabled,
                                         @RequestParam Integer recoveryIntensity,
                                         @RequestParam Integer assistIntensity,
                                         @RequestParam Boolean handleCruiseControlEnabled,
                                         @RequestParam Boolean buttonCruiseControlEnabled);*/

    @GetMapping("/iot/control/getBrakeCount/{imei}/{sn}")
    Result<Integer> getBrakeCount(@PathVariable String imei, @PathVariable String sn);

    @GetMapping("/iot/control/getBrakeDuration/{imei}/{sn}")
    Result<Integer> getBrakeDuration(@PathVariable String imei, @PathVariable String sn);

    @GetMapping("/iot/control/getSpeedPercentage/{imei}/{sn}")
    Result<Integer> getSpeedPercentage(@PathVariable String imei, @PathVariable String sn);

    @GetMapping("/iot/control/isReturnButtonClicked/{imei}/{sn}")
    Result<Boolean> isReturnButtonClicked(@PathVariable String imei, @PathVariable String sn);

    @PostMapping("/iot/control/clearReturnButtonClick/{imei}/{sn}")
    Result<Void> clearReturnButtonClick(@PathVariable String imei, @PathVariable String sn);


    // ---------- 外部端口控制 ----------
    @PostMapping("/iot/socket/openPort/{deviceCode}/{port}/{time}/{power}/{autoOpen}/{openId}") // New method with openId
    Result openPort(@PathVariable String deviceCode, @PathVariable int port, @PathVariable int time,
                    @PathVariable int power, @PathVariable int autoOpen, @PathVariable String openId);




    @GetMapping("/openManagePort")
    Result openManagePort(@RequestParam String deviceCode, @RequestParam int port, @RequestParam int time,
                          @RequestParam(required = false, defaultValue = "1000") int power,
                          @RequestParam(required = false, defaultValue = "1") int autoOpen);

    @GetMapping("/iot/socket/closePort")
    Result closePort(@RequestParam String deviceCode, @RequestParam int port);

    @GetMapping("/iot/socket/closeManagePort")
    Result closeManagePort(@RequestParam String deviceCode, @RequestParam int port);


    @PostMapping("/iot/socket/openPort") // New method with openId
    Result openPort(@RequestBody OpenSocketReq req);

    @GetMapping("/iot/socket/closePort")
    Result closePort(@RequestBody CloseSocketReq req);

}
